//
//  TravelCollectionViewCell.m
//  A段项目
//
//  Created by 刘言松 on 15/10/8.
//  Copyright (c) 2015年 刘言松. All rights reserved.
//

#import "TravelCollectionViewCell.h"
#import "UIImageView+WebCache.h"
#import "TravelModel.h"


@implementation TravelCollectionViewCell



-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    if (self) {
        
        [self addSubviews];
    }
    
    return self;
}


-(void)clickImage
{
    [self.dele clickmyItem:self.index];
}

-(void)addSubviews
{
        
    self.scrolView = [[UIScrollView alloc]initWithFrame:self.contentView.bounds];
    
    
    [self.contentView addSubview:self.scrolView];
    
    
    
    self.myImageView = [[UIImageView alloc] initWithFrame:self.bounds];
    self.myImageView.y = -0.4*self.contentView.height;
    self.myImageView.height = 1.4 * self.contentView.height;
    
    self.myImageView.contentMode = UIViewContentModeScaleAspectFill;
    self.myImageView.layer.masksToBounds = YES;
    self.myImageView.userInteractionEnabled = YES;
    [self.scrolView addSubview:self.myImageView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickImage)];
    [self.myImageView addGestureRecognizer:tap];
   
    
    self.name = [[UILabel alloc]initWithFrame:CGRectMake(self.contentView.width * 0.05, self.contentView.height * 0.05, self.contentView.width*0.9, self.contentView.height * 0.15)];
    self.name.adjustsFontSizeToFitWidth = YES;
    self.name.textColor = [UIColor whiteColor];
    self.name.font = [UIFont boldSystemFontOfSize:19];
    [self.contentView addSubview:self.name];
  
    
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(self.contentView.width * 0.05, self.name.y+self.name.height, self.contentView.width * 0.4, self.contentView.height * 0.1)];
    imageView.image = [UIImage imageNamed:@"trips_top_date_bg"];
    [self.contentView addSubview:imageView];
    
    
    self.tips = [[UILabel alloc]initWithFrame:CGRectMake(imageView.x+imageView.width*0.2, imageView.y, imageView.width, imageView.height*0.5)];
    self.tips.font = [UIFont systemFontOfSize:10 * PROPORTION];
    self.tips.textColor = [UIColor whiteColor];
    [self.contentView addSubview:self.tips];
    
    
    self.popular_place_str = [[UILabel alloc]initWithFrame:CGRectMake(imageView.x+imageView.width*0.2, imageView.y + imageView.height * 0.5, imageView.width, imageView.height*0.5)];
    self.popular_place_str.textColor = [UIColor whiteColor];
    self.popular_place_str.font = [UIFont systemFontOfSize:10* PROPORTION];
    [self.contentView addSubview:self.popular_place_str];
   
    
    self.user_avatar = [[UIImageView alloc]initWithFrame:CGRectMake(self.contentView.width * 0.1, self.contentView.height*0.8, self.contentView.width * 0.05, self.contentView.width * 0.05)];
    self.user_avatar.layer.masksToBounds = YES;
    self.user_avatar.layer.cornerRadius = self.user_avatar.width/2;
    [self.contentView addSubview:self.user_avatar];
    
    self.user_name = [[UILabel alloc]initWithFrame:CGRectMake(self.user_avatar.x + self.user_avatar.width*1.1 , self.user_avatar.y, self.contentView.width * 0.5, self.user_avatar.height)];
    self.user_name.font = [UIFont systemFontOfSize:12 * PROPORTION];
    self.user_name.textColor = [UIColor whiteColor];
    [self.contentView addSubview:self.user_name];
    
}

- (void)setData:(TravelModel *)model{
    [self.myImageView sd_setImageWithURL:[NSURL URLWithString:model.cover_image] placeholderImage:[UIImage imageNamed:@"place_holder_cell"]];
    
    self.name.text = model.name;
    
    NSString *tips = [NSString stringWithFormat:@"%@ %@天 %@次浏览",model.first_day,model.day_count,model.view_count];
    self.tips.text = tips;
    
    self.popular_place_str.text = model.popular_place_str;
    [self.user_avatar sd_setImageWithURL:[NSURL URLWithString:model.user_avatar] placeholderImage:nil];
    self.user_name.text = [NSString stringWithFormat:@"by %@",model.user_name];
}

@end
